//
//  HoHttpHelp.m
//  HOrangiOS
//
//  Created by YOrange on 2018/5/3.
//  Copyright © 2018年 YOrange. All rights reserved.
//

#import "HoHttpHelp.h"
#import <AFNetworking.h>

@implementation HoHttpHelp

-(void)post:(NSString *)url parameters:(NSDictionary *)dic{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //处理是否被下线
        [self requestFinish:responseObject];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [[self nowVc] mbShowError:error];
    }];
}

-(void)requestFinish:(NSDictionary *)response{
    ///数据请求完成
    if ([response[@"code"] isEqualToString:@"0000"]) {
        
    }else{
        [[self nowVc] mbShowToast:response[@"msg"]];
    }
}


-(BaseViewController *)nowVc{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    
    UIViewController *topVC = appRootVC;
    
    if (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    return (BaseViewController *)topVC;
}

@end
